package com.baofu.paycore.service.validate.account;

import com.baofu.paycore.manager.model.PayBaseBO;
import com.baofu.paycore.manager.storer.OrderRepository;
import com.baofu.paycore.service.facade.enums.PayStatusEnums;
import com.baofu.paycore.service.facade.model.AccountFreeze.FreezeDTO;
import com.baofu.paycore.service.facade.model.AccountFreeze.FreezeResDTO;
import com.baofu.paycore.service.validate.AbstractPayValidate;
import com.system.commons.result.Result;
import com.system.commons.utils.BeanCopyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * </p>
 * User:ames wang  Date: 2017/6/22
 */
@Slf4j
@Service
public class FreezeValidate extends AbstractPayValidate<FreezeDTO> {
    /**
     * 解冻提现参数校验
     *
     * @param t     被校验对象
     */
    public void paramsValidate(FreezeDTO t){
        super.paramsValidate(t);

    }
    /**
     * 订单唯一性校验
     *
     * @param t     被校验对象
     */
    public Result<FreezeResDTO> validateUniqueOrder(FreezeDTO t, OrderRepository orderRepository){
        PayBaseBO order = orderRepository.checkIdempotent(t.getRequestBizNo(),t.getRequestOrderNo(),t.getRequestSystem());
        if(order != null){
            FreezeResDTO freezeResDTO=BeanCopyUtil.objConvert(order,FreezeResDTO.class);
            freezeResDTO.setRealRtnFlag(Boolean.TRUE);
            freezeResDTO.setRespDate(order.getUpdatedAt());
            return new Result<>(freezeResDTO);
        }
        return null;
    }
}
